<template>
	<view style="width: 100%;display: flex;flex-direction: column;">
		<view
			style="width: 100%;display: flex;justify-content: center;color: #d3d3d3;font-size: 20rpx;margin-top: 20rpx;"
			v-if="index%8 == 0">
			{{$u.timeFormat(info.time, 'mm-dd hh:MM:ss')}}
		</view>
		<view v-if="$store.state.user.user.id != info.uid" style="width: 100%;display: flex;padding: 15rpx;">
			<u-avatar @click="gofriend" mode="square" size="80"
				:src="$store.state.common.systemInfo.fileurl + 'avatar/' + info.toid + '.jpg'"></u-avatar>
			<view style="width: 100%;display: flex;">
				<image src="/static/images/leftc.png" style="width: 25rpx;position: relative;left: 7rpx;top: 10px;"
					mode="widthFix"></image>
				<view @click="clickvideocall"
					style="max-width: 350rpx;min-height: 75rpx; display: flex;flex-wrap: wrap;white-space: pre-wrap;padding: 15rpx;border-radius: 8rpx;background: white;align-items: center;">
					<image src="/static/images/mnvdc.png" style="width: 40rpx;height: 40rpx;" mode=""></image>
					<view style="margin-left: 10rpx;font-size: 26rpx;font-weight: bold;color: #222;">
						<text>视频通话</text>
						 <!-- <text style="font-weight: normal;">[{{infox.status}}]</text> -->
					</view>
				</view>
			</view>
		</view>

		<view v-else style="width: 100%;display: flex;padding: 15rpx;flex-direction: row-reverse;">

			<u-avatar mode="square" size="80"
				:src="$store.state.common.systemInfo.fileurl + 'avatar/' + info.toid + '.jpg'"></u-avatar>
			<view style="width: 100%;display: flex;flex-direction: row-reverse;">
				<image src="/static/images/rightc.png" style="width: 25rpx;position: relative;right: 7rpx;top: 10px;"
					mode="widthFix"></image>
				<view @click="clickvideocall"
					style="max-width: 350rpx;min-height: 80rpx;display: flex;flex-wrap: wrap;white-space: pre-wrap;padding: 15rpx;border-radius: 8rpx;background: #cff1ff;align-items: center;">
					<image src="/static/images/mnvdc.png" style="width: 40rpx;height: 40rpx;" mode=""></image>
					<view style="margin-left: 10rpx;font-size: 26rpx;font-weight: bold;color: #222;">
						<text>视频通话</text>
						<!-- <text style="font-weight: normal;">[{{infox.status}}]</text> -->
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		pub,
		sub
	} from '@/common/event';
	import moment from 'moment';
	export default {
		data() {
			return {
				infox: {}
			}
		},
		mounted() {
			this.infox = this.info
			sub(`socket_videocallchange_${this.infox.id}`, (e) => {
				this.infox.status = e.status
			})
		},
		props: {
			info: {
				type: Object,
				default: () => {
					return {}
				}
			},
			index: {
				type: Number,
				default: 0
			}
		},
		computed: {
			...mapState({
				list: (state) => {

				}
			})
		},
		methods: {
			clickvideocall: function() {
				this.$emit("clickvideocall",{})
			},
			extractLink: function(text) {
				const urlRegex = /https?:\/\/(?:www\.)?[^\s/$.?#].[^\s]*/g;
				const match = text.match(urlRegex);
				return match ? match[0] : null;
			},
			handleLongpress: function(e) {
				console.log(e)
				if (moment().valueOf() - this.info.time > 60000) {
					this.actions = [{
							text: '转发',
						},
						{
							text: '复制',
						},
						{
							text: '收藏',
						},
					]
				}
			},
			gofriend: function() {
				const list = this.$store.state.friend.list
				const user = this.$store.state.user.user
				const ret = list.find(e => {
					return e.fid == this.info.uid
				})
				if (ret) {
					uni.navigateTo({
						url: "/pages/friend/detail?id=" + this.info.uid
					})
				} else {
					uni.navigateTo({
						url: "/pages/friend/friend?id=" + this.info.uid
					})
				}
			},
			csitemfunc: async function(ex) {
				const e = ex.text
				console.log(e)
				if (e == "转发") {
					uni.navigateTo({
						url: "/pages/friend/sharemessage?id=" + this.info.id
					})
				}
				if (e == "撤回") {
					const ret = await this.$u.delete(`chat/chat/removemessage/${this.info.id}`)
					uni.showToast({
						title: "已撤回",
					})
				}
				if (e == "收藏") {
					const ret = await this.$u.post(`chat/chat/collect`, this.info)
					pub("collect_done", ret.data)
					uni.showToast({
						title: "已收藏"
					})
				}
				if (e == "复制") {
					uni.setClipboardData({
						data: this.info.content,
						success: function() {
							uni.showToast({
								title: "已复制",
								icon: "success"
							})
						}
					});
				}
			},
		}
	}
</script>

<style>
</style>